#!/bin/sh

################################################################################
#    Copyright (c) 2017, 2022 Eurotech
#
#    All rights reserved. This program and the accompanying materials
#    are made available under the terms of the Eclipse Public License v1.0
#    which accompanies this distribution, and is available at
#    http://www.eclipse.org/legal/epl-v10.html
#
################################################################################

# Configure credentials

sh
#
# Continue with startup
cd /opt/artemis/

/opt/artemis/bin/artemis create \
    --allow-anonymous \
    --aio \
    --autocreate \
    --cluster-password password \
    --cluster-user user \
    --data ./data/kapua \
    --default-port 1883 \
    --home /opt/artemis \
    --host ${BINDING_IP:-0.0.0.0} \
    --name kapua \
    --password password \
    --user user \
    --verbose kapua

echo 'copying configuration...'
cp /opt/artemis/base-configuration/* /opt/artemis/kapua/etc
echo 'copying configuration... DONE'

#for the values see
# commons.eventbus.username=kapua-sys
# commons.eventbus.password=kapua-password
echo -e -n "\r\n${ARTEMIS_USER:-kapua-sys} = ENC("$(/opt/artemis/kapua/bin/artemis mask ${ARTEMIS_PASSWORD:-kapua-password} | grep "result" | cut -d" " -f2)")" >> /opt/artemis/kapua/etc/artemis-users.properties
echo -e "\r\namq = ${ARTEMIS_USER:-kapua-sys}" >> /opt/artemis/kapua/etc/artemis-roles.properties

echo 'starting Artemis...'
/opt/artemis/kapua/bin/artemis run xml:/opt/artemis/kapua/etc/bootstrap.xml